<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属商家" prop="merId">
        <el-select v-model="form.merId" placeholder="请选择所属商家" size="mini" clearable>
          <el-option v-for="shop in shopListOptions"
                     :key="shop.id"
                     :label="shop.shopName"
                     :value="shop.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="昵称" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="请输入昵称" clearable size="mini"
          @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">同步用户</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"/>
    </el-row>

    <el-table v-loading="loading" :data="mpList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="所属商家" align="center" prop="shopName" />-->
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="用户头像" align="center" prop="faceUrl" >
        <template slot-scope="scope">
          <el-image :src="scope.row.faceUrl"  style="width:50px;height:50px;"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:mp:edit']">修改</el-button>-->
<!--          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:mp:remove']">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listMp, getMp } from "@/api/module/wx/mpuser";
import { listNoPage as listNoPageMer } from "@/api/module/mer/mer";

export default {
  name: "Mp",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公众号关注的用户列表格数据
      mpList: [],
      shopListOptions:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        openId: undefined,
        unionId: undefined,
        merId: undefined,
        nickName: undefined,
        faceUrl: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getShopListOptions();
  },
  methods: {
    /** 查询公众号关注的用户列列表 */
    getList() {
      this.loading = true;
      listMp(this.queryParams).then(response => {
        this.mpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getShopListOptions(){
      listNoPageMer({isShowProduct:0}).then(res => {
        this.shopListOptions = res.data;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length!==1;
      this.multiple = !selection.length
    },
  }
};
</script>
